package com.weixin.paleituo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.bean.TemplateDetailsBean;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 样板间详情，现场实景Adapter
 *
 * @author fengzhen
 * @version v1.0, 2018/4/20
 */
public class TemplateAlbumAdapter extends RecyclerView.Adapter {
    private List<TemplateDetailsBean.Photo> mDataList;
    private Context mContext;

    public TemplateAlbumAdapter(List<TemplateDetailsBean.Photo> dataList) {
        mDataList = dataList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) mContext = parent.getContext();
        View inflate = UIUtils.inflate(parent.getContext(), R.layout.item_album_template, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        Glide.with(mContext)
                .load(mDataList.get(position).getPhotoUrl())
                .asBitmap()
                .error(R.mipmap.buffer)
                .placeholder(R.mipmap.buffer)
                .into(viewHolder.mImgItemAlbumTemplate);
    }

    @Override
    public int getItemCount() {
        return mDataList != null ? mDataList.size() : 0;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_item_album_template)
        ImageView mImgItemAlbumTemplate;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
